<!--  -->
<template>
  <div class="main">
    <h2>订单管理</h2>
    <div id="search-card">
      <div id="search-content">
        <el-form v-model="search" :inline="true">

          <el-form-item label="会员姓名">
            <el-input v-model="search.userName" />
          </el-form-item>

          <el-form-item label="机构名称">
            <el-input v-model="search.orgName" />
          </el-form-item>

          <el-form-item label="分支机构名称">
            <el-input v-model="search.campusName" />
          </el-form-item>

          <el-form-item label="服务项目">
            <el-select v-model="search.lessonId" placeholder="请选择">
              <el-option
                v-for="o in lesson"
                :key="o.lessonId"
                :value="o.lessonId"
                :label="o.lessonName"
              />
            </el-select>
            <!-- <el-input v-model="search.idCard" /> -->
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="margin-left:10px" @click="conditionQuery">查找</el-button>
          </el-form-item>

          <el-form-item label="模糊查询">
            <el-input v-model="mohu" />
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="margin-left:10px" @click="mohuQuery">查找</el-button>
          </el-form-item>
        </el-form>
      </div>

    </div>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >

        <el-table-column
          label="序号"
          type="index"
          width="80"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="id"
          label="订单编号"
        />

        <el-table-column
          align="center"
          prop="userPhone"
          label="会员手机号"
        />

        <el-table-column
          align="center"
          prop="userName"
          label="会员姓名"
        />
        <!-- <el-table-column
          align="center"
          prop="userId"
          label="用户编号"
        /> -->

        <el-table-column
          align="center"
          prop="orgName"
          label="机构名称"
        />

        <el-table-column
          align="center"
          prop="campusName"
          label="分支机构名称"
        />

        <el-table-column
          align="center"
          prop="lessonName"
          label="服务项目"
        />

        <el-table-column
          align="center"
          prop="totalPrice"
          label="总金额"
        >
          <template slot-scope="Scope">
            <span>￥{{ Scope.row.totalPrice/100 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="createTime"
          label="创建时间"
          width="100px"
        />

        <el-table-column
          align="center"
          prop="payTime"
          label="支付时间"
          width="100px"
        />

        <el-table-column
          align="center"
          prop="payType"
          label="支付方式"
          width="100px"
        >
          <template slot-scope="Scope">
            <span v-if="Scope.row.payType==0">银联支付</span>
            <span v-if="Scope.row.payType==1">分期支付</span>
            <span v-if="Scope.row.payType==2">微信支付</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="state"
          label="状态"
        >
          <template slot-scope="Scope">
            <el-tag v-if="Scope.row.state===0" type="info">待支付</el-tag>
            <el-tag v-if="Scope.row.state===1" type="success">已支付</el-tag>
          </template>

        </el-table-column>

        <el-table-column align="center" label="操作" width="120">
          <template slot-scope="Scope">
            <el-button type="primary" icon="el-icon-search" @click="handleOpen(Scope.row.id)">详细</el-button>
          </template>
        </el-table-column>

      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5,10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-dialog title="订单详情" :close-on-click-modal="false" :visible.sync="visible">
      <el-form :model="order" label-position="top">
        <el-form-item label="订单编号">
          <el-input v-model="order.id" autocomplete="off" readonly="true" />
        </el-form-item>

        <!-- <el-form-item label="用户编号">
          <el-input v-model="order.userId" autocomplete="off" readonly="true" />
        </el-form-item> -->

        <el-form-item label="机构名称">
          <el-input v-model="order.orgName" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="分支机构名称">
          <el-input v-model="order.campusName" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="服务项目名称">
          <el-input v-model="leName" autocomplete="off" readonly="true" />
          <!-- <el-select v-model="order.lessonId" disabled="">
            <el-option
              v-for="o in lesson"
              :key="o.lessonId"
              :value="o.lessonId"
              :label="o.lessonName"
            />
          </el-select> -->
        </el-form-item>
        <el-form-item label="用户姓名">
          <el-input v-model="order.userName" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="联系方式">
          <el-input v-model="order.userPhone" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="身份证">
          <el-input v-model="order.userIdCard" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="单价">
          <el-input v-model="order.singlePrice" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="数量">
          <el-input v-model="order.amount" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="总价格">
          <el-input v-model="order.totalPrice" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="创建时间">
          <el-input v-model="order.createTime" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="支付时间">
          <el-input v-model="order.payTime" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="支付方式">
          <!-- <el-input v-model="order.payType" autocomplete="off" readonly="true" /> -->
          <el-input v-if="order.payType===0" value="银联支付" autocomplete="off" readonly="true" />
          <el-input v-if="order.payType===1" value="分期支付" autocomplete="off" readonly="true" />
          <el-input v-if="order.payType===2" value="微信支付" autocomplete="off" readonly="true" />
        </el-form-item>
        <el-form-item label="状态">
          <!-- <el-input v-model="order.state" autocomplete="off" readonly="true" /> -->
          <el-input v-if="order.state===0" value="待支付" autocomplete="off" readonly="true" />
          <el-input v-if="order.state===1" value="已支付" autocomplete="off" readonly="true" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible=false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getOrdersByCampus, getOrderById, conditionSearch, mohuSearch } from '@/api/orders'
import { getAll, getById } from '@/api/class'
export default {
  name: 'Orders',
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      list: [],
      search: {},
      lesson: [],
      leName: '',
      mohu: '',
      listLoading: false,
      dialogFormVisible: false,
      order: {},
      visible: false
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.fetchData()
    this.getAllLesson()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    getAllLesson() {
      getAll().then((resp) => {
        this.lesson = resp.obj
      })
    },
    fetchData() {
      getOrdersByCampus().then((resp) => {
        this.list = resp.obj
      })
      this.listLoading = false
    },
    handleOpen(id) {
      getOrderById(id).then((resp) => {
        this.order = resp.obj
        this.order.singlePrice = this.order.singlePrice / 100
        this.order.totalPrice = this.order.totalPrice / 100
        getById(this.order.lessonId).then((resp) => {
          this.leName = resp.obj.lessonName
        })
      })
      this.visible = true
    },
    conditionQuery() {
      console.log(this.search)
      conditionSearch(this.search).then((data) => {
        this.list = data.obj
        this.search = {}
        this.currentPage = 1
      })
    },
    mohuQuery() {
      console.log(this.mohu)
      mohuSearch(this.mohu).then((data) => {
        this.list = data.obj
        this.currentPage = 1
      })
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style  scoped>

</style>
